package thread;

/**
 * @author DBX
 * @effect 终止线程的方式
 * @date 2021/8/31 0031 - 21:44
 */
public class ThreadTest1 {
    public static void main(String[] args) {
        MyThread3 t = new MyThread3();
        t.setName("8888");
        t.start();
        try {
            t.sleep(3000);
            t.run = false;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main结束");
    }
}

class MyThread3 extends Thread {
    boolean run = true;

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            if (run) {
                System.out.println(getName() + "--->" + i);
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                return;
            }
        }
    }
}